package cn.cdm.rabbitmq;


import cn.cdm.redis.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class MQSender {

    @Autowired
    AmqpTemplate amqpTemplate;

    public void send(Object message){
        String str = RedisService.beanToString(message);
        amqpTemplate.convertAndSend(MQConfig.QUEUE, str);
    }

    public void sendTopic(Object message){
        String str = RedisService.beanToString(message);
        amqpTemplate.convertAndSend(MQConfig.TOPIC_EXCHANGE, "topic.key1", message + "1");
        amqpTemplate.convertAndSend(MQConfig.TOPIC_EXCHANGE, "topic.key2", message + "2");
    }

    public void sendMiaoshaMessage(MiaoshaMessage miaoshaMessage) {
        String message = RedisService.beanToString(miaoshaMessage);
        log.info("打印：发送消息：{}", message);
        amqpTemplate.convertAndSend(MQConfig.MIAOSHA_QUEUE, message);
    }
}
